<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Manager extends Admin_Controller
{
	private static $data = array();
	public function __construct()
	{
		parent::__construct();
		$this->load->model('Admin_model','manager_model');
		$this->load->model('Role_model','role_model');
	}

	//加载页面
	public function index()
	{	    
	    $this->load->view('admin/manager/list.html');
	}
	
	//获取用户列表
    public function getList(){
        $search=$this->input->get('search');
        $page=$this->input->get('page');
        $limit=$this->input->get('limit');
        $page=$page-1;
        
        $count=$this->manager_model->getCount($search);
        $manager=$this->manager_model->getList_admin($page,$limit,$search);
        foreach ($manager as $key=>$val){
            $manager[$key]['createTime']=format_time($val['createTime']);
        }
        
        if($manager){
            show200_admin($manager,$count);
        }else{
            show400_admin();
        }
    }
    
    //添加管理员入口
    public function add(){
        $role=$this->role_model->getRoleList();
        self::$data['role']=$role;
        $this->load->view('admin/manager/add.html',self::$data);
    }
    //添加/更新管理员数据
    public function action(){
        $data=$this->input->post();
        if(isset($data['file'])){
            unset($data['file']);
        }
        if(isset($data['adminId'])&&!empty($data['adminId'])){
            //更新
            $res=$this->manager_model->update($data['adminId'],$data);
        }else{
            //添加
            $res=$this->manager_model->add($data);
        }
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    //删除
    public function del(){
        $adminIds=$this->input->post('adminIds');
        $res=$this->manager_model->del($adminIds);
        if($res){
            show200_admin([],'','操作成功');
        }else{
            show400_admin('操作失败');
        }
    }
    
    //角色 
    public function role(){
        $role=$this->role_model->getRoleList();
        self::$data['role']=$role;
        $this->load->view('admin/role/list.html',self::$data);
    }
	//编辑角色
	public function editrole(){
	    $data=$this->input->post();
	    if(isset($data['auth'])){
	        if(is_array($data['auth']));
	        $data['auth']=implode('|', $data['auth']);
	    }
	    if(isset($data['roleId'])&&!empty($data['roleId'])){
	        $res=$this->role_model->update($data['roleId'],$data);
	    }else{
	        $res=$this->role_model->add($data);
	    }
	    
	    if($res){
	       echo 200;   
	    }
	}
	//添加角色入口
	public function addrole_index(){
	    $this->load->config('menu');
	    $auth=$this->config->item('auth');
	    self::$data['auth']=$auth;
	    $this->load->view('admin/role/add.html',self::$data);
	}
	
	//删除角色
	public function delrole(){
	    $roleId=$this->input->post('roleId');
	    $res=$this->role_model->del($roleId);
	    if ($res) echo 200;
	}
	
	
	
	
	
	
	
	
	
}
/* End of file Login.php */